package com.timothy.question;

import java.util.ArrayList;
import java.util.List;

import com.timothy.android.util.XMLUtil;

public class QuestionBuilder {
	public static BaseQuestion parseQuestion(String question ) {
	    String type = XMLUtil.getPropertyValue( question , "Type");
		if( "stTwoButtonAlpha".equals( type ) ) {
			return parseSTTwoButtonAlpha( question );
		} else {
			return null;
		}
	}
	
	/**
	 *  <Question Type="stTwoButtonAlpha" SlideIndex="1" QuestionName="xxxxxxxxxxxxxxx">
	 *       <Choice Index="1" Text="True"/>
	 *       <Choice Index="2" Text="xxxx"/>
	 *  </Question>
	 * @param quesiton
	 * @return
	 */
	public static STTwoButtonAlpha parseSTTwoButtonAlpha( String quesiton ) {
		STTwoButtonAlpha q = new STTwoButtonAlpha();
		String slideIndex = XMLUtil.getPropertyValue( quesiton, "SlideIndex");
		String questName = XMLUtil.getPropertyValue( quesiton, "QuestionName");
		q.setSlideIndex( Integer.valueOf(slideIndex) );
		q.setQuestionName( questName );
		
		List<String> choices = XMLUtil.getChildren( quesiton );
		for( String choice : choices ) {
			Choice c = new Choice();
			c.setMark( XMLUtil.getPropertyValue(choice, "Index") );
			c.setContent( XMLUtil.getPropertyValue(choice, "Text") );
			q.addChoice( c ); 
		}
		
		return q;
	}
	
	public static List<BaseStation> parseBaseStation( String content ) {
		List<BaseStation> bsList = new ArrayList<BaseStation>();
		
		List<String> list = XMLUtil.getChildren( content );
		for( String s : list ) {
			BaseStation bs = new BaseStation();
			bs.setName( XMLUtil.getPropertyValue(s, "Name") );
			bsList.add( bs );
		}
		
		return bsList;
	}
}
